<template>
    <div class="section-wrap">
        <div class="form-section">
            <div class="form-item form-item-style1 paddingR12">
                <div class="label-title">
                    <label>项目名称</label>
                    <i class="iconfont icon-required"></i>
                </div>
                <p style="display:flex;align-items: center;"
                   @click="projectPropShow = true"
                   v-if="userInfo.departsir != 1">
                    <span style="color:#999;font-size:14px;">{{projectName}}</span>
                    <x-icon type="ios-arrow-right"
                            fill="#c8c8cd"
                            size="24"></x-icon>
                </p>
                <p v-else>{{userInfo.deptname}}</p>
            </div>
            <div class="form-item  form-item-style1"
                 v-if="userInfo.departsir != 1">
                <div class="label-title">
                    <label>项目经理</label>
                </div>
                <div>
                    <p>{{projectName?DutyPerson:'自动关联'}}</p>
                </div>
            </div>
            <div class="form-item  form-item-style1"
                 v-if="userInfo.departsir != 1">
                <div class="label-title">
                    <label>安全总监</label>
                </div>
                <div>
                    <p>{{projectName?SafeLeader:'自动关联'}}</p>
                </div>
            </div>
        </div>
        <div class="form-section">
            <div class="form-item  form-item-style1 paddingR12">
                <div class="label-title">
                    <label>带班领导</label>
                    <i class="iconfont icon-required"></i>
                </div>
                <p style="display:flex;align-items: center;"
                   @click="copyUserNameShow = true">
                    <span style="color:#999;font-size:14px;">{{leader?leader:'请选择'}}</span>
                    <x-icon type="ios-arrow-right"
                            fill="#c8c8cd"
                            size="24"></x-icon>
                </p>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>所属单位</label>
                </div>
                <div>
                    <p>{{DeptName?DeptName:'自动关联'}}</p>
                </div>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>职务</label>
                </div>
                <div>
                    <p>{{UserKind?UserKind:'自动关联'}}</p>
                </div>
            </div>
        </div>
        <div class="form-section">
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>带班时间</label>
                </div>
                <group>
                    <datetime v-model="startDate"></datetime>
                </group>
            </div>
            <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>检查人员</label>
                        <i class="iconfont icon-required"></i>
                    </div>
                    <span @click="personPropShow = true">请选择</span>
                </div>
                <div>
                    <p class="textarea">{{checkPerson}}</p>
                </div>
            </div>
            <div class="form-item form-item-style2">
                <div class="label-title">
                    <label>带班记事</label>
                    <i class="iconfont icon-required"></i>
                </div>
                <div>
                    <textarea placeholder="请输入"
                              v-model="baseInformation"></textarea>
                </div>
            </div>
            <div class="form-item form-item-style2">
                <div class="label-title space-between">
                    <div class="space-between">
                        <label>检查图片</label>
                        <i class="iconfont icon-required"></i>
                    </div>
                    <span>当前共{{uploadLength}}张图片</span>
                </div>
                <div class="upload-wrap">
                    <upload @setFormData="setFormData"></upload>
                </div>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>记录人</label>
                </div>
                <div>
                    <p>{{this.userInfo.username}}</p>
                </div>
            </div>
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>记录时间</label>
                </div>
                <div>
                    <p>{{recordTime}}</p>
                </div>
            </div>
            <div class="btns">
                <button class="green width200"
                        @click="submit">提交</button>
            </div>
        </div>
        <!-- <departUserAllProp :leaderPropShow="leaderPropShow"
                           :selectLeaderFn="selectLeaderFn"></departUserAllProp> -->
        <copyUserNameProp :copyUserNameShow="copyUserNameShow"
                          :selectCopyUserName="selectLeaderFn"
                          :single="true"></copyUserNameProp>
        <FBProp :selectFBFn="selectProjectFn"
                :FBPropShow="projectPropShow"
                :type="0"></FBProp>
        <checkUserProp :personPropShow="personPropShow"
                       :selectUsers="selectUsers"></checkUserProp>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import formatDate from '@/utils/formatDate'
import upload from '@/commonComponents/upload/index'
import copyUserNameProp from '@/commonComponents/copyUserNameProp'
import FBProp from '@/commonComponents/FBProp'
import checkUserProp from '@/commonComponents/checkUserProp'
export default {
    name: 'addLeadershipWork',
    components: {
        upload,
        copyUserNameProp,
        FBProp,
        checkUserProp,
        myMenu
    },
    data () {
        return {
            userInfo: '',
            copyUserNameShow: false,
            projectPropShow: false,
            personPropShow: false,
            projectId: '', // 项目id
            projectName: '', // 项目名称
            DutyPerson: '', // 项目经理
            SafeLeader: '', // 安全总监
            SafeLeaderId: '', // 总监ID
            UserKind: '', // 职务
            DeptNameId: '', // 所属单位Id
            DeptName: '', // 所属单位
            leader: '', // 带班领导
            baseInformation: '', // 带班记事
            checkPerson: '', // 检查人员
            recordTime: formatDate(),
            uploadLength: 0,
            uploadImgFormData: null,
            startDate: formatDate()
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
        if (this.userInfo.departsir == '1') {
            this.projectName = this.userInfo.deptname
            this.projectId = this.userInfo.deptid
        }
    },
    methods: {
        setFormData (formData, uploadLength) {
            this.uploadImgFormData = formData
            this.uploadLength = uploadLength
        },
        submit () {
            if (!this.projectName) {
                this.$vux.toast.text('请选择项目')
                return false
            } else if (!this.leader) {
                this.$vux.toast.text('请选择带班领导')
                return false
            } else if (!this.checkPerson) {
                this.$vux.toast.text('请选择检查人员')
                return false
            } else if (!this.baseInformation) {
                this.$vux.toast.text('请输入带班记事')
                return false
            }
            this.$vux.loading.show({
                text: '提交中，请稍等...'
            })
            let param = {
                'allowPaging': true,
                'business': 'InsertWorkRecord',
                'data': {
                    'arrowState': false,
                    'ProjectManager': this.DutyPerson, // 项目经理名称
                    'SafeManager': this.SafeLeader, // 安全总监名称
                    'SafeManagerID': this.SafeLeaderId, // 安全总监id
                    'LeaderCategory': this.UserKind, // 职务
                    'LeaderDeptID': this.DeptNameId, // 所属单位id
                    'LeaderDeptName': this.DeptName, // 所属单位名称
                    'baseInformation': this.baseInformation, // 带班记事
                    'checkPerson': this.checkPerson, // 检查人员
                    'createDate': formatDate(), // 记录时间
                    'createUser': this.userInfo.username,
                    'createdByDeptId': this.userInfo.deptid,
                    'leader': this.leader, // 带班领导
                    'projectId': this.projectId, // 项目ID
                    'projectName': this.projectName, // 项目名称
                    'startDate': this.startDate// 带班时间
                },
                'method': 'new',
                'pageIndex': 0,
                'pageSize': 0,
                'tokenId': this.userInfo.tokenid,
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(
                param,
                this.uploadImgFormData
            ).then((res) => {
                if (res.data.code == 0) {
                    this.$vux.toast.text('新增成功')
                    setTimeout(() => {
                        this.$router.go(-1)
                    }, 500)
                }
            })
        },
        selectLeaderFn (item) {
            this.copyUserNameShow = false
            this.leader = item.Name
            this.DeptNameId = item.ParentId
            this.DeptName = item.DeptName
            this.UserKind = item.UserKind
        },
        selectProjectFn (item) { // 选择项目
            this.projectPropShow = false
            this.projectName = item.deptName
            this.projectId = item.deptId
            this.DutyPerson = item.DutyPerson // 项目经理
            this.SafeLeader = item.SafeLeader // 安全总监
            this.SafeLeaderId = item.SafeLeaderId // 总监id
        },
        selectUsers (checkPerson) { //  检查人员
            this.personPropShow = false
            this.checkPerson = checkPerson
        }
    }
}
</script>
<style scoped>
</style>
